package com.bby.disk.util;

import com.bby.common.config.GlobalSettings;

import java.io.File;

public class BBYFileSystem {
    static File root;
    static {
        root = new File(GlobalSettings.ROOT_PATH,"data");
        if (!root.exists()){
            root.mkdirs();
        }
    }
    private static File distDir(String md5){
        File dir = new File(root,md5.substring(0, 2) + File.separator +
                md5.substring(2, 4) + File.separator +
                md5.substring(4, 6) + File.separator);
        if (!dir.exists()){
            dir.mkdirs();
        }
        return dir;
    }
    public static boolean add(File file,String md5){
        File dist = new File(distDir(md5),md5);
        if (dist.isFile()) return true;
        return file.renameTo(dist);
    }
    public static boolean del(String md5){
        return new File(distDir(md5),md5).delete();
    }
    public static File get(String md5){
        return new File(distDir(md5),md5);
    }
    public static void main(String[] args) {
        File file = new File("F:\\新建文本文档.txt");
        System.out.println(add(file,"ASADSAfZXas"));
        System.out.println(file);
        System.out.println(file.delete());
    }
}
